package com.jeecms.wicool.dao.groupBuy.impl;

import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.wicool.dao.groupBuy.GroupBuySpecificationDao;
import com.jeecms.wicool.entity.groupBuy.GroupBuySpecification;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by cuiyanlei on 15/6/10.
 */
@Repository
public class GroupBuySpecificationDaoImpl extends HibernateBaseDao<GroupBuySpecification, Integer> implements GroupBuySpecificationDao {
    @Override
    public GroupBuySpecification save(GroupBuySpecification bean) {
        getSession().save(bean);
        return bean;
    }

    @Override
    public GroupBuySpecification deleteById(Integer id) {
        GroupBuySpecification bean = get(id);
        if (bean != null) {
            getSession().delete(bean);
        }
        return bean;
    }

    @Override
    public GroupBuySpecification findById(Integer id) {
        return get(id);
    }

    @Override
    public List<GroupBuySpecification> getAll(Integer foreignId) {
        Finder f = Finder.create(" select bean from GroupBuySpecification bean where 1=1 ");
        f.append(" and bean.groupBuy.id=:group_buy_id ").setParam("group_buy_id", foreignId);
        f.append(" order by bean.id ");
        return find(f);
    }

    @Override
    protected Class<GroupBuySpecification> getEntityClass() {
        return GroupBuySpecification.class;
    }
}
